using System;
using System.Data;
using System.Data.OleDb;
using PCSComUtils.Common;
using PCSComUtils.DataAccess;

using PCSComUtils.PCSExc;

namespace PCSComProcurement.Purchase.DS
{
	public class PO_FunctionVendorReferenceDS
	{
		public PO_FunctionVendorReferenceDS()
		{
		}

		private const string THIS = "PCSComProcurement.Purchase.DS.PO_FunctionVendorReferenceDS";


		//**************************************************************************              
		///    <Description>
		///       This method uses to add data to PO_FunctionVendorReference
		///    </Description>
		///    <Inputs>
		///        PO_FunctionVendorReferenceVO       
		///    </Inputs>
		///    <Outputs>
		///       newly inserted primarkey value
		///    </Outputs>
		///    <Returns>
		///       void
		///    </Returns>
		///    <Authors>
		///       HungLa
		///       DungLa
		///    </Authors>
		///    <History>
		///       Monday, April 04, 2005
		///       10/05/2005: added more fields
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public void Add(object pobjObjectVO)
		{
			const string METHOD_NAME = THIS + ".Add()";

			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;
			try
			{
				PO_FunctionVendorReferenceVO objObject = (PO_FunctionVendorReferenceVO) pobjObjectVO;
				string strSql = String.Empty;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand("", oconPCS);

				strSql = "INSERT INTO " + PO_FunctionVendorReferenceTable.TABLE_NAME + "("
					+ PO_FunctionVendorReferenceTable.CCNID_FLD + ","
					+ PO_FunctionVendorReferenceTable.VENDORFUNCTION_FLD + ","
					+ PO_FunctionVendorReferenceTable.FIXEDLEADTIME_FLD + ","
					+ PO_FunctionVendorReferenceTable.VARIANCELEADTIME_FLD + ","
					+ PO_FunctionVendorReferenceTable.PRICE_FLD + ","
					+ PO_FunctionVendorReferenceTable.ENDDATE_FLD + ","
					+ PO_FunctionVendorReferenceTable.QUANTITY_FLD + ","
					+ PO_FunctionVendorReferenceTable.MINORDERQUANTITY_FLD + ","
					+ PO_FunctionVendorReferenceTable.CURRENCYID_FLD + ","
					+ PO_FunctionVendorReferenceTable.VENDORID_FLD + ","
					+ PO_FunctionVendorReferenceTable.VENDORLOCID_FLD + ","
					+ PO_FunctionVendorReferenceTable.FUNCTIONID_FLD + ","
					+ PO_FunctionVendorReferenceTable.CAPACITY_FLD + ","
					+ PO_FunctionVendorReferenceTable.CAPACITYPERIOD_FLD + ","
					+ PO_FunctionVendorReferenceTable.CARRIERID_FLD + ")"
					+ "VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_FunctionVendorReferenceTable.CCNID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.CCNID_FLD].Value = objObject.CCNID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_FunctionVendorReferenceTable.VENDORFUNCTION_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.VENDORFUNCTION_FLD].Value = objObject.VendorFunction;

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_FunctionVendorReferenceTable.FIXEDLEADTIME_FLD, OleDbType.Decimal));
				if (objObject.FixedLeadTime != -1)
				{
					ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.FIXEDLEADTIME_FLD].Value = objObject.FixedLeadTime;
				}
				else
				{
					ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.FIXEDLEADTIME_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_FunctionVendorReferenceTable.VARIANCELEADTIME_FLD, OleDbType.Decimal));
				if (objObject.VarianceLeadTime != -1)
				{
					ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.VARIANCELEADTIME_FLD].Value = objObject.VarianceLeadTime;
				}
				else
				{
					ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.VARIANCELEADTIME_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_FunctionVendorReferenceTable.PRICE_FLD, OleDbType.Decimal));
				if (objObject.Price != -1)
				{
					ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.PRICE_FLD].Value = objObject.Price;
				}
				else
				{
					ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.PRICE_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_FunctionVendorReferenceTable.ENDDATE_FLD, OleDbType.Date));
				ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.ENDDATE_FLD].Value = objObject.EndDate;

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_FunctionVendorReferenceTable.QUANTITY_FLD, OleDbType.Decimal));
				if (objObject.Quantity != -1)
				{
					ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.QUANTITY_FLD].Value = objObject.Quantity;
				}
				else
				{
					ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.QUANTITY_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_FunctionVendorReferenceTable.MINORDERQUANTITY_FLD, OleDbType.Decimal));
				if (objObject.MinOrderQuantity != -1)
				{
					ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.MINORDERQUANTITY_FLD].Value = objObject.MinOrderQuantity;
				}
				else
				{
					ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.MINORDERQUANTITY_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_FunctionVendorReferenceTable.CURRENCYID_FLD, OleDbType.Integer));
				if (objObject.CurrencyID != -1)
				{
					ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.CURRENCYID_FLD].Value = objObject.CurrencyID;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_FunctionVendorReferenceTable.VENDORID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.VENDORID_FLD].Value = objObject.VendorID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_FunctionVendorReferenceTable.VENDORLOCID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.VENDORLOCID_FLD].Value = objObject.VendorLocID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_FunctionVendorReferenceTable.FUNCTIONID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.FUNCTIONID_FLD].Value = objObject.FunctionID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_ItemVendorReferenceTable.CAPACITY_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters.Add(new OleDbParameter(PO_ItemVendorReferenceTable.CAPACITYPERIOD_FLD, OleDbType.VarWChar));
				
				if (objObject.Capacity != -1)
				{
					ocmdPCS.Parameters[PO_ItemVendorReferenceTable.CAPACITY_FLD].Value = objObject.Capacity;
					ocmdPCS.Parameters[PO_ItemVendorReferenceTable.CAPACITYPERIOD_FLD].Value = objObject.CapacityPeriod;
				}
				else
				{
					ocmdPCS.Parameters[PO_ItemVendorReferenceTable.CAPACITY_FLD].Value = DBNull.Value;
					ocmdPCS.Parameters[PO_ItemVendorReferenceTable.CAPACITYPERIOD_FLD].Value = DBNull.Value;						
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_FunctionVendorReferenceTable.CARRIERID_FLD, OleDbType.Integer));
				if (objObject.CarrierID != -1)
				{
					ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.CARRIERID_FLD].Value = objObject.CarrierID;
				}
				else
				{
					ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.CARRIERID_FLD].Value = DBNull.Value;
				}


				ocmdPCS.CommandText = strSql;
				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();

			}
			catch (OleDbException ex)
			{
				if (ex.Errors.Count > 0)
				{
					if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
					{
						throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);
					}
					else
					{
						throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
					}
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
				}
			}

			catch (InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
			}
			catch (Exception ex)
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally
			{
				if (oconPCS != null)
				{
					if (oconPCS.State != ConnectionState.Closed)
					{
						oconPCS.Close();
					}
				}
			}
		}


		//**************************************************************************              
		///    <Description>
		///       This method uses to delete data from PO_FunctionVendorReference
		///    </Description>
		///    <Inputs>
		///        ID       
		///    </Inputs>
		///    <Outputs>
		///       void
		///    </Outputs>
		///    <Returns>
		///       
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       09-Dec-2004
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public void Delete(int pintID)
		{
			const string METHOD_NAME = THIS + ".Delete()";
			string strSql = String.Empty;
			strSql = "DELETE " + PO_FunctionVendorReferenceTable.TABLE_NAME + " WHERE  " + "FunctionVendorReferenceID" + "=" + pintID.ToString();
			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;
			try
			{
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);

				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();
				ocmdPCS = null;

			}
			catch (OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
				{
					throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
				}
			}

			catch (Exception ex)
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}


			finally
			{
				if (oconPCS != null)
				{
					if (oconPCS.State != ConnectionState.Closed)
					{
						oconPCS.Close();
					}
				}
			}
		}


		//**************************************************************************              
		///    <Description>
		///       This method uses to get data from PO_FunctionVendorReference
		///    </Description>
		///    <Inputs>
		///        ID       
		///    </Inputs>
		///    <Outputs>
		///       PO_FunctionVendorReferenceVO
		///    </Outputs>
		///    <Returns>
		///       PO_FunctionVendorReferenceVO
		///    </Returns>
		///    <Authors>
		///       HungLa
		///       DungLa
		///    </Authors>
		///    <History>
		///       Monday, April 04, 2005
		///       10/05/2005 - add more fields
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public object GetObjectVO(int pintID)
		{
			const string METHOD_NAME = THIS + ".GetObjectVO()";
			DataSet dstPCS = new DataSet();

			OleDbDataReader odrPCS = null;
			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;
			try
			{
				string strSql = String.Empty;
				strSql = "SELECT "
					+ PO_FunctionVendorReferenceTable.FUNCTIONVENDORREFERENCEID_FLD + ","
					+ PO_FunctionVendorReferenceTable.CCNID_FLD + ","
					+ PO_FunctionVendorReferenceTable.VENDORFUNCTION_FLD + ","
					+ PO_FunctionVendorReferenceTable.FIXEDLEADTIME_FLD + ","
					+ PO_FunctionVendorReferenceTable.VARIANCELEADTIME_FLD + ","
					+ PO_FunctionVendorReferenceTable.PRICE_FLD + ","
					+ PO_FunctionVendorReferenceTable.ENDDATE_FLD + ","
					+ PO_FunctionVendorReferenceTable.QUANTITY_FLD + ","
					+ PO_FunctionVendorReferenceTable.MINORDERQUANTITY_FLD + ","
					+ PO_FunctionVendorReferenceTable.CURRENCYID_FLD + ","
					+ PO_FunctionVendorReferenceTable.VENDORID_FLD + ","
					+ PO_FunctionVendorReferenceTable.VENDORLOCID_FLD + ","
					+ PO_FunctionVendorReferenceTable.FUNCTIONID_FLD + ","
					+ PO_FunctionVendorReferenceTable.CAPACITY_FLD + ","
					+ PO_FunctionVendorReferenceTable.CAPACITYPERIOD_FLD + ","
					+ PO_FunctionVendorReferenceTable.CARRIERID_FLD
					+ " FROM " + PO_FunctionVendorReferenceTable.TABLE_NAME
					+ " WHERE " + PO_FunctionVendorReferenceTable.FUNCTIONVENDORREFERENCEID_FLD + "=" + pintID;

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);

				ocmdPCS.Connection.Open();
				odrPCS = ocmdPCS.ExecuteReader();

				PO_FunctionVendorReferenceVO objObject = new PO_FunctionVendorReferenceVO();

				while (odrPCS.Read())
				{
					objObject.FunctionVendorReferenceID = int.Parse(odrPCS[PO_FunctionVendorReferenceTable.FUNCTIONVENDORREFERENCEID_FLD].ToString().Trim());
					if (odrPCS[PO_FunctionVendorReferenceTable.CCNID_FLD] != DBNull.Value)
						objObject.CCNID = int.Parse(odrPCS[PO_FunctionVendorReferenceTable.CCNID_FLD].ToString().Trim());
					objObject.VendorFunction = odrPCS[PO_FunctionVendorReferenceTable.VENDORFUNCTION_FLD].ToString().Trim();
					if (odrPCS[PO_FunctionVendorReferenceTable.FIXEDLEADTIME_FLD].ToString() != string.Empty)
					{
						objObject.FixedLeadTime = Decimal.Parse(odrPCS[PO_FunctionVendorReferenceTable.FIXEDLEADTIME_FLD].ToString().Trim());
					}
					else
					{
						objObject.FixedLeadTime = -1;
					}

					if (odrPCS[PO_FunctionVendorReferenceTable.VARIANCELEADTIME_FLD].ToString() != string.Empty)
					{
						objObject.VarianceLeadTime = Decimal.Parse(odrPCS[PO_FunctionVendorReferenceTable.VARIANCELEADTIME_FLD].ToString().Trim());
					}
					else
					{
						objObject.VarianceLeadTime = -1;
					}

					if (odrPCS[PO_FunctionVendorReferenceTable.PRICE_FLD].ToString() != string.Empty)
					{
						objObject.Price = Decimal.Parse(odrPCS[PO_FunctionVendorReferenceTable.PRICE_FLD].ToString().Trim());
					}
					else
					{
						objObject.Price = -1;
					}


					if (odrPCS[PO_FunctionVendorReferenceTable.ENDDATE_FLD] != DBNull.Value)
						objObject.EndDate = DateTime.Parse(odrPCS[PO_FunctionVendorReferenceTable.ENDDATE_FLD].ToString().Trim());
					if (odrPCS[PO_FunctionVendorReferenceTable.QUANTITY_FLD].ToString() != string.Empty)
					{
						objObject.Quantity = Decimal.Parse(odrPCS[PO_FunctionVendorReferenceTable.QUANTITY_FLD].ToString().Trim());
					}
					else
					{
						objObject.Quantity = -1;
					}

					if (odrPCS[PO_FunctionVendorReferenceTable.MINORDERQUANTITY_FLD].ToString() != string.Empty)
					{
						objObject.MinOrderQuantity = Decimal.Parse(odrPCS[PO_FunctionVendorReferenceTable.MINORDERQUANTITY_FLD].ToString().Trim());
					}
					else
					{
						objObject.MinOrderQuantity = -1;
					}

					if (odrPCS[PO_FunctionVendorReferenceTable.CURRENCYID_FLD] != DBNull.Value)
						objObject.CurrencyID = int.Parse(odrPCS[PO_FunctionVendorReferenceTable.CURRENCYID_FLD].ToString().Trim());
					if (odrPCS[PO_FunctionVendorReferenceTable.VENDORID_FLD] != DBNull.Value)
						objObject.VendorID = int.Parse(odrPCS[PO_FunctionVendorReferenceTable.VENDORID_FLD].ToString().Trim());
					if (odrPCS[PO_FunctionVendorReferenceTable.VENDORLOCID_FLD] != DBNull.Value)
						objObject.VendorLocID = int.Parse(odrPCS[PO_FunctionVendorReferenceTable.VENDORLOCID_FLD].ToString().Trim());
					if (odrPCS[PO_FunctionVendorReferenceTable.FUNCTIONID_FLD] != DBNull.Value)
						objObject.FunctionID = int.Parse(odrPCS[PO_FunctionVendorReferenceTable.FUNCTIONID_FLD].ToString().Trim());
					if (odrPCS[PO_ItemVendorReferenceTable.CAPACITY_FLD] != DBNull.Value)
						objObject.Capacity = Decimal.Parse(odrPCS[PO_ItemVendorReferenceTable.CAPACITY_FLD].ToString().Trim());
					objObject.CapacityPeriod = odrPCS[PO_ItemVendorReferenceTable.CAPACITYPERIOD_FLD].ToString().Trim();
					if (odrPCS[PO_FunctionVendorReferenceTable.CARRIERID_FLD].ToString() != string.Empty)
					{
						objObject.CarrierID = int.Parse(odrPCS[PO_FunctionVendorReferenceTable.CARRIERID_FLD].ToString().Trim());
					}
				}
				return objObject;
			}
			catch (OleDbException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
			}

			catch (Exception ex)
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally
			{
				if (oconPCS != null)
				{
					if (oconPCS.State != ConnectionState.Closed)
					{
						oconPCS.Close();
					}
				}
			}
		}

		//**************************************************************************              
		///    <Description>
		///       This method uses to get data from PO_FunctionVendorReference
		///    </Description>
		///    <Inputs>
		///        ID       
		///    </Inputs>
		///    <Outputs>
		///       PO_FunctionVendorReferenceVO
		///    </Outputs>
		///    <Returns>
		///       PO_FunctionVendorReferenceVO
		///    </Returns>
		///    <Authors>
		///       HungLa
		///       DungLa
		///    </Authors>
		///    <History>
		///       Monday, April 04, 2005
		///       10/05/2005: added more fields
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public object GetObjectVO(int pintVendorID, int pintFunctionID)
		{
			const string METHOD_NAME = THIS + ".GetObjectVO()";
			DataSet dstPCS = new DataSet();

			OleDbDataReader odrPCS = null;
			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;
			try
			{
				string strSql = String.Empty;
				strSql = "SELECT "
					+ PO_FunctionVendorReferenceTable.FUNCTIONVENDORREFERENCEID_FLD + ","
					+ PO_FunctionVendorReferenceTable.CCNID_FLD + ","
					+ PO_FunctionVendorReferenceTable.VENDORFUNCTION_FLD + ","
					+ PO_FunctionVendorReferenceTable.FIXEDLEADTIME_FLD + ","
					+ PO_FunctionVendorReferenceTable.VARIANCELEADTIME_FLD + ","
					+ PO_FunctionVendorReferenceTable.PRICE_FLD + ","
					+ PO_FunctionVendorReferenceTable.ENDDATE_FLD + ","
					+ PO_FunctionVendorReferenceTable.QUANTITY_FLD + ","
					+ PO_FunctionVendorReferenceTable.MINORDERQUANTITY_FLD + ","
					+ PO_FunctionVendorReferenceTable.CURRENCYID_FLD + ","
					+ PO_FunctionVendorReferenceTable.VENDORID_FLD + ","
					+ PO_FunctionVendorReferenceTable.VENDORLOCID_FLD + ","
					+ PO_FunctionVendorReferenceTable.FUNCTIONID_FLD + ","
					+ PO_FunctionVendorReferenceTable.CAPACITY_FLD + ","
					+ PO_FunctionVendorReferenceTable.CAPACITYPERIOD_FLD + ","
					+ PO_FunctionVendorReferenceTable.CARRIERID_FLD
					+ " FROM " + PO_FunctionVendorReferenceTable.TABLE_NAME
					+ " WHERE " + PO_FunctionVendorReferenceTable.FUNCTIONID_FLD + "=" + pintFunctionID.ToString() + " and " + PO_FunctionVendorReferenceTable.VENDORID_FLD + " = " + pintVendorID.ToString();

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);

				ocmdPCS.Connection.Open();
				odrPCS = ocmdPCS.ExecuteReader();

				PO_FunctionVendorReferenceVO objObject = new PO_FunctionVendorReferenceVO();

				while (odrPCS.Read())
				{
					objObject.FunctionVendorReferenceID = int.Parse(odrPCS[PO_FunctionVendorReferenceTable.FUNCTIONVENDORREFERENCEID_FLD].ToString().Trim());
					if (odrPCS[PO_FunctionVendorReferenceTable.CCNID_FLD] != DBNull.Value)
						objObject.CCNID = int.Parse(odrPCS[PO_FunctionVendorReferenceTable.CCNID_FLD].ToString().Trim());
					objObject.VendorFunction = odrPCS[PO_FunctionVendorReferenceTable.VENDORFUNCTION_FLD].ToString().Trim();
					if (odrPCS[PO_FunctionVendorReferenceTable.FIXEDLEADTIME_FLD].ToString() != string.Empty)
					{
						objObject.FixedLeadTime = Decimal.Parse(odrPCS[PO_FunctionVendorReferenceTable.FIXEDLEADTIME_FLD].ToString().Trim());
					}
					else
					{
						objObject.FixedLeadTime = -1;
					}

					if (odrPCS[PO_FunctionVendorReferenceTable.VARIANCELEADTIME_FLD].ToString() != string.Empty)
					{
						objObject.VarianceLeadTime = Decimal.Parse(odrPCS[PO_FunctionVendorReferenceTable.VARIANCELEADTIME_FLD].ToString().Trim());
					}
					else
					{
						objObject.VarianceLeadTime = -1;
					}

					if (odrPCS[PO_FunctionVendorReferenceTable.PRICE_FLD].ToString() != string.Empty)
					{
						objObject.Price = Decimal.Parse(odrPCS[PO_FunctionVendorReferenceTable.PRICE_FLD].ToString().Trim());
					}
					else
					{
						objObject.Price = -1;
					}


					if (odrPCS[PO_FunctionVendorReferenceTable.ENDDATE_FLD] != DBNull.Value)
						objObject.EndDate = DateTime.Parse(odrPCS[PO_FunctionVendorReferenceTable.ENDDATE_FLD].ToString().Trim());
					if (odrPCS[PO_FunctionVendorReferenceTable.QUANTITY_FLD].ToString() != string.Empty)
					{
						objObject.Quantity = Decimal.Parse(odrPCS[PO_FunctionVendorReferenceTable.QUANTITY_FLD].ToString().Trim());
					}
					else
					{
						objObject.Quantity = -1;
					}

					if (odrPCS[PO_FunctionVendorReferenceTable.MINORDERQUANTITY_FLD].ToString() != string.Empty)
					{
						objObject.MinOrderQuantity = Decimal.Parse(odrPCS[PO_FunctionVendorReferenceTable.MINORDERQUANTITY_FLD].ToString().Trim());
					}
					else
					{
						objObject.MinOrderQuantity = -1;
					}

					if (odrPCS[PO_FunctionVendorReferenceTable.CURRENCYID_FLD] != DBNull.Value)
						objObject.CurrencyID = int.Parse(odrPCS[PO_FunctionVendorReferenceTable.CURRENCYID_FLD].ToString().Trim());
					if (odrPCS[PO_FunctionVendorReferenceTable.VENDORID_FLD] != DBNull.Value)
						objObject.VendorID = int.Parse(odrPCS[PO_FunctionVendorReferenceTable.VENDORID_FLD].ToString().Trim());
					if (odrPCS[PO_FunctionVendorReferenceTable.VENDORLOCID_FLD] != DBNull.Value)
						objObject.VendorLocID = int.Parse(odrPCS[PO_FunctionVendorReferenceTable.VENDORLOCID_FLD].ToString().Trim());
					if (odrPCS[PO_FunctionVendorReferenceTable.FUNCTIONID_FLD] != DBNull.Value)
						objObject.FunctionID = int.Parse(odrPCS[PO_FunctionVendorReferenceTable.FUNCTIONID_FLD].ToString().Trim());
					if (odrPCS[PO_ItemVendorReferenceTable.CAPACITY_FLD] != DBNull.Value)
					{
						objObject.Capacity = Decimal.Parse(odrPCS[PO_ItemVendorReferenceTable.CAPACITY_FLD].ToString().Trim());
					}
					else
					{
						objObject.Capacity = -1;
					}
					objObject.CapacityPeriod = odrPCS[PO_ItemVendorReferenceTable.CAPACITYPERIOD_FLD].ToString().Trim();
					if (odrPCS[PO_FunctionVendorReferenceTable.CARRIERID_FLD].ToString() != string.Empty)
					{
						objObject.CarrierID = int.Parse(odrPCS[PO_FunctionVendorReferenceTable.CARRIERID_FLD].ToString().Trim());
					}
				}
				return objObject;
			}
			catch (OleDbException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
			}

			catch (Exception ex)
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally
			{
				if (oconPCS != null)
				{
					if (oconPCS.State != ConnectionState.Closed)
					{
						oconPCS.Close();
					}
				}
			}
		}


		//**************************************************************************              
		///    <Description>
		///       This method uses to update data to PO_FunctionVendorReference
		///    </Description>
		///    <Inputs>
		///       PO_FunctionVendorReferenceVO       
		///    </Inputs>
		///    <Outputs>
		///       
		///    </Outputs>
		///    <Returns>
		///       
		///    </Returns>
		///    <Authors>
		///       HungLa
		///       DungLa
		///    </Authors>
		///    <History>
		///       09-Dec-2004
		///       10/05/2005: update more fields
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public void Update(object pobjObjecVO)
		{
			const string METHOD_NAME = THIS + ".Update()";

			PO_FunctionVendorReferenceVO objObject = (PO_FunctionVendorReferenceVO) pobjObjecVO;


			//prepare value for parameters
			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;
			try
			{
				string strSql = String.Empty;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				strSql = "UPDATE PO_FunctionVendorReference SET "
					+ PO_FunctionVendorReferenceTable.CCNID_FLD + "=   ?" + ","
					+ PO_FunctionVendorReferenceTable.VENDORFUNCTION_FLD + "=   ?" + ","
					+ PO_FunctionVendorReferenceTable.FIXEDLEADTIME_FLD + "=   ?" + ","
					+ PO_FunctionVendorReferenceTable.VARIANCELEADTIME_FLD + "=   ?" + ","
					+ PO_FunctionVendorReferenceTable.PRICE_FLD + "=   ?" + ","
					+ PO_FunctionVendorReferenceTable.ENDDATE_FLD + "=   ?" + ","
					+ PO_FunctionVendorReferenceTable.QUANTITY_FLD + "=   ?" + ","
					+ PO_FunctionVendorReferenceTable.MINORDERQUANTITY_FLD + "=   ?" + ","
					+ PO_FunctionVendorReferenceTable.CURRENCYID_FLD + "=   ?" + ","
					+ PO_FunctionVendorReferenceTable.VENDORID_FLD + "=   ?" + ","
					+ PO_FunctionVendorReferenceTable.VENDORLOCID_FLD + "=   ?" + ","
					+ PO_FunctionVendorReferenceTable.FUNCTIONID_FLD + "=   ?" + ","
					+ PO_FunctionVendorReferenceTable.CAPACITY_FLD + "=   ?" + ","
					+ PO_FunctionVendorReferenceTable.CAPACITYPERIOD_FLD + "=   ?" + ","
					+ PO_FunctionVendorReferenceTable.CARRIERID_FLD + "=  ?"
					+ " WHERE " + PO_FunctionVendorReferenceTable.FUNCTIONVENDORREFERENCEID_FLD + "= ?";

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_FunctionVendorReferenceTable.CCNID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.CCNID_FLD].Value = objObject.CCNID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_FunctionVendorReferenceTable.VENDORFUNCTION_FLD, OleDbType.VarWChar));
				ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.VENDORFUNCTION_FLD].Value = objObject.VendorFunction;

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_FunctionVendorReferenceTable.FIXEDLEADTIME_FLD, OleDbType.Decimal));
				if (objObject.FixedLeadTime != -1)
				{
					ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.FIXEDLEADTIME_FLD].Value = objObject.FixedLeadTime;
				}
				else
				{
					ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.FIXEDLEADTIME_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_FunctionVendorReferenceTable.VARIANCELEADTIME_FLD, OleDbType.Decimal));
				if (objObject.VarianceLeadTime != -1)
				{
					ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.VARIANCELEADTIME_FLD].Value = objObject.VarianceLeadTime;
				}
				else
				{
					ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.VARIANCELEADTIME_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_FunctionVendorReferenceTable.PRICE_FLD, OleDbType.Decimal));
				if (objObject.Price != -1)
				{
					ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.PRICE_FLD].Value = objObject.Price;
				}
				else
				{
					ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.PRICE_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_FunctionVendorReferenceTable.ENDDATE_FLD, OleDbType.Date));
				ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.ENDDATE_FLD].Value = objObject.EndDate;

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_FunctionVendorReferenceTable.QUANTITY_FLD, OleDbType.Decimal));
				if (objObject.Quantity != -1)
				{
					ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.QUANTITY_FLD].Value = objObject.Quantity;
				}
				else
				{
					ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.QUANTITY_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_FunctionVendorReferenceTable.MINORDERQUANTITY_FLD, OleDbType.Decimal));
				if (objObject.MinOrderQuantity != -1)
				{
					ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.MINORDERQUANTITY_FLD].Value = objObject.MinOrderQuantity;
				}
				else
				{
					ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.MINORDERQUANTITY_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_FunctionVendorReferenceTable.CURRENCYID_FLD, OleDbType.Integer));
				if (objObject.CurrencyID != -1)
				{
					ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.CURRENCYID_FLD].Value = objObject.CurrencyID;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_FunctionVendorReferenceTable.VENDORID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.VENDORID_FLD].Value = objObject.VendorID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_FunctionVendorReferenceTable.VENDORLOCID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.VENDORLOCID_FLD].Value = objObject.VendorLocID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_FunctionVendorReferenceTable.FUNCTIONID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.FUNCTIONID_FLD].Value = objObject.FunctionID;

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_ItemVendorReferenceTable.CAPACITY_FLD, OleDbType.Decimal));
				ocmdPCS.Parameters.Add(new OleDbParameter(PO_ItemVendorReferenceTable.CAPACITYPERIOD_FLD, OleDbType.VarWChar));
				
				if (objObject.Capacity != -1)
				{
					ocmdPCS.Parameters[PO_ItemVendorReferenceTable.CAPACITY_FLD].Value = objObject.Capacity;
					ocmdPCS.Parameters[PO_ItemVendorReferenceTable.CAPACITYPERIOD_FLD].Value = objObject.CapacityPeriod;
				}
				else
				{
					ocmdPCS.Parameters[PO_ItemVendorReferenceTable.CAPACITY_FLD].Value = DBNull.Value;
					ocmdPCS.Parameters[PO_ItemVendorReferenceTable.CAPACITYPERIOD_FLD].Value = DBNull.Value;						
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_FunctionVendorReferenceTable.CARRIERID_FLD, OleDbType.Integer));
				if (objObject.CarrierID != -1)
				{
					ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.CARRIERID_FLD].Value = objObject.CarrierID;
				}
				else
				{
					ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.CARRIERID_FLD].Value = DBNull.Value;
				}

				ocmdPCS.Parameters.Add(new OleDbParameter(PO_FunctionVendorReferenceTable.FUNCTIONVENDORREFERENCEID_FLD, OleDbType.Integer));
				ocmdPCS.Parameters[PO_FunctionVendorReferenceTable.FUNCTIONVENDORREFERENCEID_FLD].Value = objObject.FunctionVendorReferenceID;


				ocmdPCS.CommandText = strSql;
				ocmdPCS.Connection.Open();
				ocmdPCS.ExecuteNonQuery();
			}
			catch (OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);
				}
				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
				}
			}

			catch (InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
			}
			catch (Exception ex)
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally
			{
				if (oconPCS != null)
				{
					if (oconPCS.State != ConnectionState.Closed)
					{
						oconPCS.Close();
					}
				}
			}

		}


		//**************************************************************************              
		///    <Description>
		///       This method uses to get all data from PO_FunctionVendorReference
		///    </Description>
		///    <Inputs>
		///               
		///    </Inputs>
		///    <Outputs>
		///       DataSet
		///    </Outputs>
		///    <Returns>
		///       DataSet
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Monday, April 04, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public DataSet List()
		{
			const string METHOD_NAME = THIS + ".List()";
			DataSet dstPCS = new DataSet();


			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;
			try
			{
				string strSql = String.Empty;

				strSql = "SELECT "
					+ PO_FunctionVendorReferenceTable.FUNCTIONVENDORREFERENCEID_FLD + ","
					+ PO_FunctionVendorReferenceTable.CCNID_FLD + ","
					+ PO_FunctionVendorReferenceTable.VENDORFUNCTION_FLD + ","
					+ PO_FunctionVendorReferenceTable.FIXEDLEADTIME_FLD + ","
					+ PO_FunctionVendorReferenceTable.VARIANCELEADTIME_FLD + ","
					+ PO_FunctionVendorReferenceTable.PRICE_FLD + ","
					+ PO_FunctionVendorReferenceTable.ENDDATE_FLD + ","
					+ PO_FunctionVendorReferenceTable.QUANTITY_FLD + ","
					+ PO_FunctionVendorReferenceTable.MINORDERQUANTITY_FLD + ","
					+ PO_FunctionVendorReferenceTable.CURRENCYID_FLD + ","
					+ PO_FunctionVendorReferenceTable.VENDORID_FLD + ","
					+ PO_FunctionVendorReferenceTable.VENDORLOCID_FLD + ","
					+ PO_FunctionVendorReferenceTable.FUNCTIONID_FLD + ","
					+ PO_FunctionVendorReferenceTable.CAPACITY_FLD + ","
					+ PO_FunctionVendorReferenceTable.CAPACITYPERIOD_FLD + ","
					+ PO_FunctionVendorReferenceTable.CARRIERID_FLD
					+ " FROM " + PO_FunctionVendorReferenceTable.TABLE_NAME;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				ocmdPCS.Connection.Open();

				OleDbDataAdapter odadPCS = new OleDbDataAdapter(ocmdPCS);
				odadPCS.Fill(dstPCS, PO_FunctionVendorReferenceTable.TABLE_NAME);

				return dstPCS;
			}
			catch (OleDbException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
			}
			catch (Exception ex)
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally
			{
				if (oconPCS != null)
				{
					if (oconPCS.State != ConnectionState.Closed)
					{
						oconPCS.Close();
					}
				}
			}
		}

		//**************************************************************************              
		///    <Description>
		///       This method uses to get all data from PO_FunctionVendorReference
		///    </Description>
		///    <Inputs>
		///               
		///    </Inputs>
		///    <Outputs>
		///       DataSet
		///    </Outputs>
		///    <Returns>
		///       DataSet
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Monday, April 04, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public DataSet ListFunctionVendorCrossReference(int pintCCNID, int pintVendorID, int pintVendorLocID)
		{
			const string METHOD_NAME = THIS + ".ListFunctionVendorCrossReference()";
			DataSet dstPCS = new DataSet();

			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;
			try
			{
				string strSql = String.Empty;

				strSql = "SELECT "
					+ PO_FunctionVendorReferenceTable.FUNCTIONVENDORREFERENCEID_FLD + ","
					+ PO_FunctionVendorReferenceTable.CCNID_FLD + ","
					+ "(SELECT " + MST_FunctionTable.CODE_FLD + " FROM " + MST_FunctionTable.TABLE_NAME + " WHERE " + MST_FunctionTable.FUNCTIONID_FLD + "=" + PO_FunctionVendorReferenceTable.TABLE_NAME + "." + PO_FunctionVendorReferenceTable.FUNCTIONID_FLD + ") as " + MST_FunctionTable.TABLE_NAME + MST_FunctionTable.CODE_FLD + ","
					+ PO_FunctionVendorReferenceTable.VENDORFUNCTION_FLD + ","
					+ PO_FunctionVendorReferenceTable.FIXEDLEADTIME_FLD + ","
					+ PO_FunctionVendorReferenceTable.VARIANCELEADTIME_FLD + ","
					+ PO_FunctionVendorReferenceTable.PRICE_FLD + ","
					+ PO_FunctionVendorReferenceTable.QUANTITY_FLD + ","
					+ PO_FunctionVendorReferenceTable.ENDDATE_FLD + ","
					+ PO_FunctionVendorReferenceTable.MINORDERQUANTITY_FLD + ","
					+ PO_FunctionVendorReferenceTable.CURRENCYID_FLD + ","
					+ PO_FunctionVendorReferenceTable.VENDORID_FLD + ","
					+ PO_FunctionVendorReferenceTable.VENDORLOCID_FLD + ","
					+ PO_FunctionVendorReferenceTable.FUNCTIONID_FLD + ","
					+ PO_FunctionVendorReferenceTable.CAPACITY_FLD + ","
					+ PO_FunctionVendorReferenceTable.CAPACITYPERIOD_FLD + ","
					+ PO_FunctionVendorReferenceTable.CARRIERID_FLD
					+ " FROM " + PO_FunctionVendorReferenceTable.TABLE_NAME
					+ " WHERE " + PO_FunctionVendorReferenceTable.CCNID_FLD + " = " + pintCCNID.ToString() + " and "
					+ PO_FunctionVendorReferenceTable.VENDORID_FLD + " = " + pintVendorID.ToString() + " and " + PO_FunctionVendorReferenceTable.VENDORLOCID_FLD + " = " + pintVendorLocID.ToString();
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				ocmdPCS.Connection.Open();

				OleDbDataAdapter odadPCS = new OleDbDataAdapter(ocmdPCS);
				odadPCS.Fill(dstPCS, PO_FunctionVendorReferenceTable.TABLE_NAME);

				return dstPCS;
			}
			catch (OleDbException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
			}
			catch (Exception ex)
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally
			{
				if (oconPCS != null)
				{
					if (oconPCS.State != ConnectionState.Closed)
					{
						oconPCS.Close();
					}
				}
			}
		}


		//**************************************************************************              
		///    <Description>
		///       This method uses to update a DataSet
		///    </Description>
		///    <Inputs>
		///        DataSet       
		///    </Inputs>
		///    <Outputs>
		///       
		///    </Outputs>
		///    <Returns>
		///       
		///    </Returns>
		///    <Authors>
		///       HungLa
		///    </Authors>
		///    <History>
		///       Monday, April 04, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public void UpdateDataSet(DataSet pData)
		{
			const string METHOD_NAME = THIS + ".UpdateDataSet()";
			string strSql;
			OleDbConnection oconPCS = null;
			OleDbCommandBuilder odcbPCS;
			OleDbDataAdapter odadPCS = new OleDbDataAdapter();

			try
			{
				strSql = "SELECT "
					+ PO_FunctionVendorReferenceTable.FUNCTIONVENDORREFERENCEID_FLD + ","
					+ PO_FunctionVendorReferenceTable.CCNID_FLD + ","
					+ PO_FunctionVendorReferenceTable.VENDORFUNCTION_FLD + ","
					+ PO_FunctionVendorReferenceTable.FIXEDLEADTIME_FLD + ","
					+ PO_FunctionVendorReferenceTable.VARIANCELEADTIME_FLD + ","
					+ PO_FunctionVendorReferenceTable.PRICE_FLD + ","
					+ PO_FunctionVendorReferenceTable.ENDDATE_FLD + ","
					+ PO_FunctionVendorReferenceTable.QUANTITY_FLD + ","
					+ PO_FunctionVendorReferenceTable.MINORDERQUANTITY_FLD + ","
					+ PO_FunctionVendorReferenceTable.CURRENCYID_FLD + ","
					+ PO_FunctionVendorReferenceTable.VENDORID_FLD + ","
					+ PO_FunctionVendorReferenceTable.VENDORLOCID_FLD + ","
					+ PO_FunctionVendorReferenceTable.FUNCTIONID_FLD + ","
					+ PO_FunctionVendorReferenceTable.CAPACITY_FLD + ","
					+ PO_FunctionVendorReferenceTable.CAPACITYPERIOD_FLD + ","
					+ PO_FunctionVendorReferenceTable.CARRIERID_FLD
					+ "  FROM " + PO_FunctionVendorReferenceTable.TABLE_NAME;

				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				odadPCS.SelectCommand = new OleDbCommand(strSql, oconPCS);
				odcbPCS = new OleDbCommandBuilder(odadPCS);
				pData.EnforceConstraints = false;
				odadPCS.Update(pData, PO_FunctionVendorReferenceTable.TABLE_NAME);

			}
			catch (OleDbException ex)
			{
				if (ex.Errors[1].NativeError == ErrorCode.SQLDUPLICATE_KEYCODE)
				{
					throw new PCSDBException(ErrorCode.DUPLICATE_KEY, METHOD_NAME, ex);
				}
				else if (ex.Errors[1].NativeError == ErrorCode.SQLCASCADE_PREVENT_KEYCODE)
				{
					throw new PCSDBException(ErrorCode.CASCADE_DELETE_PREVENT, METHOD_NAME, ex);
				}

				else
				{
					throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
				}
			}

			catch (InvalidOperationException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
			}
			catch (Exception ex)
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally
			{
				if (oconPCS != null)
				{
					if (oconPCS.State != ConnectionState.Closed)
					{
						oconPCS.Close();
					}
				}
			}

		}

		//**************************************************************************              
		///    <Description>
		///       This method uses to get all data from from specific table with expression
		///    </Description>
		///    <Inputs>
		///               
		///    </Inputs>
		///    <Outputs>
		///       DataTable
		///    </Outputs>
		///    <Returns>
		///       DataTable
		///    </Returns>
		///    <Authors>
		///       DungLa
		///    </Authors>
		///    <History>
		///       April 07, 2005
		///    </History>
		///    <Notes>
		///    </Notes>
		//**************************************************************************
		public DataTable GetRows(string pstrTableName, string pstrExpression)
		{
			const string METHOD_NAME = THIS + ".GetRows()";
			DataSet dstPCS = new DataSet();

			OleDbConnection oconPCS = null;
			OleDbCommand ocmdPCS = null;
			try
			{
				string strSql = String.Empty;

				strSql = "SELECT * "
					+ " FROM " + pstrTableName;
				if ((pstrExpression.Trim() != string.Empty) && (pstrExpression != null))
					strSql += " " + pstrExpression;
				
				oconPCS = new OleDbConnection(Utils.Instance.OleDbConnectionString);
				ocmdPCS = new OleDbCommand(strSql, oconPCS);
				ocmdPCS.Connection.Open();

				OleDbDataAdapter odadPCS = new OleDbDataAdapter(ocmdPCS);
				odadPCS.Fill(dstPCS, pstrTableName);

				return dstPCS.Tables[0];
			}
			catch (OleDbException ex)
			{
				throw new PCSDBException(ErrorCode.ERROR_DB, METHOD_NAME, ex);
			}
			catch (Exception ex)
			{
				throw new PCSDBException(ErrorCode.OTHER_ERROR, METHOD_NAME, ex);
			}

			finally
			{
				if (oconPCS != null)
				{
					if (oconPCS.State != ConnectionState.Closed)
					{
						oconPCS.Close();
					}
				}
			}
		}
	}
}